package com.lvshou.medicalkit.utils;

import com.common.libhttp.retrofit.RetrofitManager;
import com.lvshou.medicalkit.model.ApiService;

/**
 * 网络请求工具
 */
public class HttpClient {

    private static ApiService apiService;
    public static ApiService getApiService() {
        return apiService == null ? apiService = builder(ApiService.class) : apiService;
    }

    /**
     * 获得对应的ApiServcie对象
     *
     * @param service
     * @param <T>
     * @return
     */
    public static <T> T builder(Class<T> service) {
        return RetrofitManager.getInstance().getRetrofit().create(service);

    }

    /**
     * 获得对应的ApiServcie对象
     *
     * @param baseUrl
     * @return
     */
//    public static <T> T builder(Class<T> service, String baseUrl) {
//        if (baseUrl == null) {
//            throw new RuntimeException("baseUrl is null!");
//        }
//        Retrofit retrofit = new Retrofit.Builder()
//                .baseUrl(baseUrl)
//                .client(OkHttpHelper.getClient())
//                .addConverterFactory(StringConverterFactory.create()) //String 转换
//                .addConverterFactory(GsonConverterFactory.create())
//                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
//                .validateEagerly(true)
//                .build();
//        return retrofit.create(service);
//
//    }

}
